<?php
	include 'config.php';
	set_time_limit(0);
	@date_default_timezone_set('Asia/Shanghai');
	
	function curlrequest($url,$postfield,$proxy=""){
		$proxy=trim($proxy);
		$user_agent ="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
		$ch = curl_init(); 
		if(!empty($proxy)){
			curl_setopt($ch, CURLOPT_PROXY, $proxy);
		}
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $postfield);
		curl_setopt($ch, CURLOPT_TIMEOUT, 25);
		curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
	
		$document = curl_exec($ch);
		$info=curl_getinfo($ch);
		#print_r($info);
		if($info[http_code]=="405"){
			echo "bad proxy {$proxy}\n"; //代理出错
			exit;
		}
		//curl_close($ch);
		return $document;
	}
	
	//请求URL
	$url = str_replace('?','',$url);
				//遍历商品属性
			if(!empty($_POST['prov'])){				
				foreach($_POST["prov"] as $value){
					$props = $props.$value.";";  
				}
			}
				//遍历商品属性
			if(!empty($_POST['input_pids'])){
				foreach($_POST["input_pids"] as $value){
					$input_pids = $input_pids.$value.",";  
				}
			}

			if(!empty($_POST['input_str'])){			
				//遍历商品属性
				foreach($_POST["input_str"] as $value){
					$input_str = $input_str.$value.",";  
				}	
			}							

    //准备本次请求参数
	$curtime = date('Y-m-d H:i:s'); //时间戳
	$fields= 'modified,iid,num_iid'; //fields

	$format = 'xml';  //设定返回数据格式
	$method = 'taobao.item.update'; //请求API名称
	$iid = $_POST['iid']; //商品iid

    $desc = $_POST['desc']; //接收desc	
	$postage_id = $_POST['postage_id']; //运费模板ID
	$input_pids = $input_pids;
	$input_str = $input_str;
	$props = $props; //商品属性串
	$seller_cids = $_POST['seller_cids']; //店铺自定义分类
		
	$paramArr = array(
		/* API系统级输入参数 Start */

	    	'method' => $method,  //API名称
		   'session' => $sessions, //session
	     'timestamp' => $curtime,			
		    'format' => 'xml',  //返回格式,本demo仅支持xml
    	   'app_key' => $appKey,  //Appkey			
	    		 'v' => '2.0',   //API版本号		   
		'sign_method'=> 'md5', //签名方式			

		/* API系统级参数 End */				 

		/* API应用级输入参数 Start*/

			'fields' => 'modified,num_iid',
      'num_iid' => $iid,			
			   'desc' => $desc,
	   'seller_cids' => $seller_cids,
	       'input_str' => $input_str,
		 'input_pids' => $input_pids,
	  'postage_id' => $postage_id,
	      'props' => $props,
			
		/* API应用级输入参数 End*/
	);

	//生成签名
	$sign = createSign($paramArr,$appSecret);		
 

	
	$strParam = createStrParam($paramArr);
	$strParam .= 'sign='.$sign;
	$proxy = '';
	$str = curlrequest($url,$strParam,$proxy);
	$str = getXmlData($str);
		
?>
<pre>
<?php 

if($str['msg']){
	echo '更新失败,'.$str['sub_msg'];
}else{
	echo '更新成功,<a href="http://mini.tbsandbox.com/minisandbox/buyer/item_detail.htm?numIid='.$iid.'" target="_blank">查看</a>';
}

?>
</pre>